import argparse
import subprocess
import platform
# Function to open ITK-SNAP with a specified file
def showmsh(filename):
    module = "gmsh" #if platform.system() == 'Windows' else "itksnap"
    try:
        # Use subprocess to run the itk-snap command
        subprocess.run([module, '-g', filename], check=True)
        print(f"gmsh opened file: {filename}")
    except subprocess.CalledProcessError as e:
        print(f"Error running gmsh: {e}")
    except FileNotFoundError:
        print("gmsh not found. Please ensure it is installed and in your PATH.")

# Main function with argument parsing
def main():
    parser = argparse.ArgumentParser(description="Open a mesh file using gmsh")
    parser.add_argument('--filename', required=True, help="Path to the mesh file to open in gmsh")
    
    # Parse the command-line arguments
    args = parser.parse_args()
    
    # Call the function to open ITK-SNAP with the provided filename
    open_itk_snap(args.filename)

if __name__ == "__main__":
    main()
